package com.clz.servlet;

import com.clz.servise.Impl.UserServiceImpl;
import com.clz.servise.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/SessionLogin")
public class SessionLoginServlet extends HttpServlet {
    private UserService userService=new UserServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       String name=req.getParameter("username");
       String password=req.getParameter("password");
       if (userService.login(name, password)){
           HttpSession session =req.getSession();
           session.setAttribute("username",name);
           resp.sendRedirect("/admin/adminMain.jsp");
       }else {
           resp.sendRedirect("login.html?login=false1");
       }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
